<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.1.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"chenmenghui.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
<meta property="og:type" content="website">
<meta property="og:title" content="陈孟辉的学习笔记">
<meta property="og:url" content="https://chenmenghui.gitee.io/page/13/index.html">
<meta property="og:site_name" content="陈孟辉的学习笔记">
<meta property="og:description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="陈孟辉">
<meta property="article:tag" content="开发菜鸟 陈孟辉">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://chenmenghui.gitee.io/page/13/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>陈孟辉的学习笔记</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/rss2.xml" title="陈孟辉的学习笔记" type="application/rss+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">陈孟辉的学习笔记</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">加油吧骚年</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-rss">

    <a href="/rss2.xml" rel="section"><i class="fa fa-rss fa-fw"></i>RSS</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/16665.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/16665.html" class="post-title-link" itemprop="url">C++基本语法</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-03-09 00:00:00" itemprop="dateCreated datePublished" datetime="2019-03-09T00:00:00+08:00">2019-03-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/C/" itemprop="url" rel="index"><span itemprop="name">C++</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/16665.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/16665.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>814</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="基本语法"><a href="#基本语法" class="headerlink" title="基本语法"></a>基本语法</h1><p>C++程序可以定义为对象的集合,这些对象通过调用彼此的方法进行交互.</p>
<ul>
<li>对象 对象具有状态和行为</li>
<li>类 类可以定义为描述对象&#x2F;行为的状态&#x2F;蓝图</li>
<li>方法 一个方法表示一个行为.一个类可以有多个方法.可以在方法中写入逻辑\操作数据以及执行所有的动作</li>
<li>即使变量 每个对象都有其独特的即使变量.对象的状态是有这些即使变量的值创建的</li>
</ul>
<h1 id="程序结构"><a href="#程序结构" class="headerlink" title="程序结构"></a>程序结构</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span>   <span class="comment">// C++定义的一些头文件,这些头文件包含了程序中必须的或有用的信息</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std; <span class="comment">// 命名空间</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> <span class="comment">// 主函数 程序开始的地方</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    cout &lt;&lt; <span class="string">&quot;Hello world&quot;</span>; <span class="comment">// print</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>; <span class="comment">// 终止main()函数,并向调用进程返回值0</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="编译-amp-执行程序"><a href="#编译-amp-执行程序" class="headerlink" title="编译&amp;执行程序"></a>编译&amp;执行程序</h1><ul>
<li>打开一个文本编辑器,添加上述代码</li>
<li>保存文件</li>
<li>打开命令行,进入文件所在目录</li>
<li>键入’g++ hello.cp’,输入回车,编译代码.若代码没有错误,命令提示符会跳到下一行,并生成a.out可执行文件</li>
<li>键入’a.out’运行</li>
<li>可看到输出结果</li>
</ul>
<h1 id="分号-amp-语句块"><a href="#分号-amp-语句块" class="headerlink" title="分号&amp;语句块"></a>分号&amp;语句块</h1><p>‘;’是语句结束符<br>语句块是一组大括号括起来的按逻辑链接的语句</p>
<h1 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h1><p>标识符用来标识变量 函数 类 模块或其他用户自定义项目的名称,和php一样</p>
<h1 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h1><table>
<thead>
<tr>
<th>保留字</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>asm</td>
<td>指令字符串:允许程序中嵌入汇编代码</td>
</tr>
<tr>
<td>auto</td>
<td>自动:存储类型标识符,表示变量”自动”具有本地范围,块范围的变量声明默认为auto存储类型</td>
</tr>
<tr>
<td>bool</td>
<td>布尔类型</td>
</tr>
<tr>
<td>break</td>
<td>跳出,用于switch或循环语句中</td>
</tr>
<tr>
<td>case</td>
<td>用于switch语句中,判断条件类</td>
</tr>
<tr>
<td>catch</td>
<td>和try一起用于异常处理</td>
</tr>
<tr>
<td>char</td>
<td>字节类型</td>
</tr>
<tr>
<td>class</td>
<td>类</td>
</tr>
<tr>
<td>const</td>
<td>常量</td>
</tr>
<tr>
<td>continue</td>
<td>循环语句,跳出当前循环</td>
</tr>
<tr>
<td>default</td>
<td>用于switch中</td>
</tr>
<tr>
<td>delete</td>
<td>释放程序动态申请的内存</td>
</tr>
<tr>
<td>do</td>
<td>循环</td>
</tr>
<tr>
<td>double</td>
<td>双精度</td>
</tr>
<tr>
<td>else</td>
<td>if</td>
</tr>
<tr>
<td>enum</td>
<td>枚举</td>
</tr>
<tr>
<td>explicit</td>
<td></td>
</tr>
</tbody></table>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/42291.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/42291.html" class="post-title-link" itemprop="url">小程序中多个倒计时</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-02-25 00:00:00" itemprop="dateCreated datePublished" datetime="2019-02-25T00:00:00+08:00">2019-02-25</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js/" itemprop="url" rel="index"><span itemprop="name">js</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/42291.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/42291.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// pages/test/test.js</span></span><br><span class="line"><span class="title class_">Page</span>(&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 页面的初始数据</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">data</span>: &#123;</span><br><span class="line">        <span class="attr">times</span>: [</span><br><span class="line">            <span class="string">&quot;2019-02-26 16:14:58&quot;</span>,</span><br><span class="line">            <span class="string">&quot;2019-03-24 16:34:58&quot;</span>,</span><br><span class="line">            <span class="string">&quot;2019-02-27 16:14:58&quot;</span>,</span><br><span class="line">            <span class="string">&quot;2019-02-24 12:14:58&quot;</span>,</span><br><span class="line">        ],</span><br><span class="line">        <span class="attr">count_downs</span>: [],</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 生命周期函数--监听页面显示</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">onShow</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">        <span class="title function_">countDown</span>(<span class="variable language_">this</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> timepiece = &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 时间戳转化成时间</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> <span class="variable">stamp</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@returns</span> &#123;<span class="type">string</span>&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">stamp2time</span>: <span class="keyword">function</span> (<span class="params">stamp</span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> d = <span class="keyword">new</span> <span class="title class_">Date</span>(stamp * <span class="number">1000</span>);    <span class="comment">//根据时间戳生成的时间对象</span></span><br><span class="line">        <span class="keyword">var</span> date = (d.<span class="title function_">getFullYear</span>()) + <span class="string">&quot;-&quot;</span> +</span><br><span class="line">            (d.<span class="title function_">getMonth</span>() + <span class="number">1</span>) + <span class="string">&quot;-&quot;</span> +</span><br><span class="line">            (d.<span class="title function_">getDate</span>()) + <span class="string">&quot; &quot;</span> +</span><br><span class="line">            (d.<span class="title function_">getHours</span>()) + <span class="string">&quot;:&quot;</span> +</span><br><span class="line">            (d.<span class="title function_">getMinutes</span>()) + <span class="string">&quot;:&quot;</span> +</span><br><span class="line">            (d.<span class="title function_">getSeconds</span>());</span><br><span class="line">        <span class="keyword">return</span> date;</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 时间转化成时间戳</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> <span class="variable">stamp</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@returns</span> &#123;<span class="type">number</span>&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">time2stamp</span>: <span class="keyword">function</span> (<span class="params">time</span>) &#123;</span><br><span class="line">        time = time.<span class="title function_">substring</span>(<span class="number">0</span>, <span class="number">19</span>);</span><br><span class="line">        time = time.<span class="title function_">replace</span>(<span class="regexp">/-/g</span>, <span class="string">&#x27;/&#x27;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="keyword">new</span> <span class="title class_">Date</span>(time).<span class="title function_">getTime</span>() / <span class="number">1000</span>);</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 秒转化成时分秒的形式</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> <span class="variable">second</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">second2hour</span>: <span class="keyword">function</span> (<span class="params">value</span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> secondTime = <span class="built_in">parseInt</span>(value);</span><br><span class="line">        <span class="keyword">var</span> minuteTime = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">var</span> hourTime = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span> (secondTime &gt; <span class="number">60</span>) &#123;</span><br><span class="line">            minuteTime = <span class="built_in">parseInt</span>(secondTime / <span class="number">60</span>);</span><br><span class="line">            secondTime = <span class="built_in">parseInt</span>(secondTime % <span class="number">60</span>);</span><br><span class="line">            <span class="keyword">if</span> (minuteTime &gt; <span class="number">60</span>) &#123;</span><br><span class="line">                hourTime = <span class="built_in">parseInt</span>(minuteTime / <span class="number">60</span>);</span><br><span class="line">                minuteTime = <span class="built_in">parseInt</span>(minuteTime % <span class="number">60</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (hourTime &lt; <span class="number">10</span>) &#123;</span><br><span class="line">            hourTime = <span class="string">`0<span class="subst">$&#123;hourTime&#125;</span>`</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (minuteTime &lt; <span class="number">10</span>) &#123;</span><br><span class="line">            minuteTime = <span class="string">`0<span class="subst">$&#123;minuteTime&#125;</span>`</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (secondTime &lt; <span class="number">10</span>) &#123;</span><br><span class="line">            secondTime = <span class="string">`0<span class="subst">$&#123;secondTime&#125;</span>`</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">var</span> result = <span class="string">`<span class="subst">$&#123;hourTime&#125;</span>:<span class="subst">$&#123;minuteTime&#125;</span>:<span class="subst">$&#123;secondTime&#125;</span>`</span>;</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 时间和当前时间的差值</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> <span class="variable">time</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="attr">remain</span>: <span class="keyword">function</span> (<span class="params">time</span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> now = <span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="keyword">new</span> <span class="title class_">Date</span>().<span class="title function_">getTime</span>() / <span class="number">1000</span>);</span><br><span class="line">        time = <span class="variable language_">this</span>.<span class="title function_">time2stamp</span>(time);</span><br><span class="line">        time = time - now;</span><br><span class="line">        <span class="keyword">if</span> (time &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">            time = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="title function_">second2hour</span>(time);</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 倒计时</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> <span class="variable">that</span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> <span class="variable">times</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> countDown = <span class="keyword">function</span> (<span class="params">that</span>) &#123;</span><br><span class="line">    <span class="built_in">setInterval</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> counts = [];</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> that.<span class="property">data</span>.<span class="property">times</span>) &#123;</span><br><span class="line">            counts[i] = timepiece.<span class="title function_">remain</span>(that.<span class="property">data</span>.<span class="property">times</span>[i])</span><br><span class="line">        &#125;</span><br><span class="line">        that.<span class="title function_">setData</span>(&#123;</span><br><span class="line">            <span class="attr">count_downs</span>: counts</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;, <span class="number">1000</span>);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/18839.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/18839.html" class="post-title-link" itemprop="url">延迟静态绑定</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-02-13 00:00:00" itemprop="dateCreated datePublished" datetime="2019-02-13T00:00:00+08:00">2019-02-13</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/PHP/" itemprop="url" rel="index"><span itemprop="name">PHP</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/18839.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/18839.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>后期静态绑定，用于在继承范围内引用静态调用的类。</p>
<p>后期静态绑定工作原理是存储了在上一个“非转发调用”（non-forwarding call）的类名。当进行静态方法调用时，该类名即为明确指定的那个（通常在 :: 运算符左侧部分）；当进行非静态方法调用时，即为该对象所属的类。所谓的“转发调用”（forwarding call）指的是通过以下几种方式进行的静态调用：self::，parent::，static:: 以及 forward_static_call()。可用 get_called_class() 函数来得到被调用的方法所在的类名，static:: 则指出了其范围。</p>
<p>转发调用:<br>self:: 所在类<br>parent:: 父类<br>static:: 调用类</p>
<p>后期静态绑定的解析会一直到取得一个完全解析了的静态调用为止。另一方面，如果静态调用使用 parent:: 或者 self:: 将转发调用信息</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="built_in">static</span>::<span class="title function_ invoke__">who</span>(); <span class="comment">// 留意此处,static究竟指向谁</span></span><br><span class="line">        <span class="comment">// 如果是self::who(),就都是A了.这就是特别需要注意的地方</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">static</span> <span class="function"><span class="keyword">function</span> <span class="title">who</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="built_in">static</span>::<span class="variable language_">class</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="keyword">__CLASS__</span> . <span class="string">&quot;\n&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">static</span> <span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        A::<span class="title function_ invoke__">foo</span>(); <span class="comment">// 非转发调用</span></span><br><span class="line">        <span class="built_in">static</span>::<span class="title function_ invoke__">foo</span>();</span><br><span class="line">        <span class="built_in">parent</span>::<span class="title function_ invoke__">foo</span>(); <span class="comment">//</span></span><br><span class="line">        <span class="built_in">self</span>::<span class="title function_ invoke__">foo</span>();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">static</span> <span class="function"><span class="keyword">function</span> <span class="title">who</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="built_in">static</span>::<span class="variable language_">class</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="keyword">__CLASS__</span> . <span class="string">&quot;\n&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span> <span class="keyword">extends</span> <span class="title">B</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">C::<span class="title function_ invoke__">test</span>();</span><br><span class="line"></span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>

<p>运行结果</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">AA</span><br><span class="line">CB</span><br><span class="line">CB</span><br><span class="line">CB</span><br></pre></td></tr></table></figure>

<p>对于方法who()中<br>static::class是调用类的类名<br>__CLASS__是对象实例所属类的类名</p>
<p>个人对运行结果的看法</p>
<p>第一个AA<br>    1. C::test() &#x3D;&gt; C-&gt;B::test(){A::foo()}<br>    2. A::foo(){static::who()} &#x3D;&gt; A::who()</p>
<p>第二个CB<br>    1. C::test() &#x3D;&gt; C-&gt;B::test(){<em>static::foo()</em>}<br>    2. C-&gt;B::test(){static::foo()} &#x3D;&gt; C-&gt;B-&gt;A::foo(){static::who()} &#x3D; C::who() &#x3D; C-&gt;B::who() # 类C没有foo,所以向最近的被继承类中找</p>
<p>第三个CB<br>    1. C::test() &#x3D;&gt; C-&gt;B::test(){<em>parent::foo()</em>}<br>    2. C-&gt;B-&gt;A::foo(){static::who()} &#x3D;&gt; C-&gt;B::who() # 直接找类A中的foo</p>
<p>第三个CB<br>    1. C::test() &#x3D;&gt; C-&gt;B::test(){<em>self::foo()</em>}<br>    2. C-&gt;B-&gt;A::foo(){static::who()} &#x3D;&gt; C-&gt;B::who() # 类B没有foo,所以向最近的被继承类中找</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/64199.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/64199.html" class="post-title-link" itemprop="url">MySQL机读顺序</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-01-26 00:00:00" itemprop="dateCreated datePublished" datetime="2019-01-26T00:00:00+08:00">2019-01-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/64199.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/64199.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>315</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p><a target="_blank" rel="noopener" href="https://blog.csdn.net/u014044812/article/details/51004754/">关于sql和MySQL的语句执行顺序</a></p>
<ol>
<li><p>FROM <left_table></p>
</li>
<li><p>ON <join_condition></p>
</li>
<li><p><join_type> JOIN <right_table></p>
</li>
<li><p>WHERE <where_condition></p>
</li>
<li><p>GROUP BY <group_by_list></p>
</li>
<li><p>HAVING <having_condition></p>
</li>
<li><p>select</p>
</li>
<li><p>DISTINCT <select_list></p>
</li>
<li><p>ORDER BY <order_by_condition></p>
</li>
<li><p>LIMIT <limit_number></p>
</li>
</ol>
<h3 id="having"><a href="#having" class="headerlink" title="having"></a>having</h3><p>The SQL standard requires that HAVING must reference only columns in the GROUP BY clause or columns used in aggregate functions. However, MySQL supports an extension to this behavior, and permits HAVING to refer to columns in the SELECT list and columns in outer sub-queries as well.</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/40296.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/40296.html" class="post-title-link" itemprop="url">MySQL分组函数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-01-26 00:00:00" itemprop="dateCreated datePublished" datetime="2019-01-26T00:00:00+08:00">2019-01-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/40296.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/40296.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>75</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>select 分组函数,列(要求列出现在group by后面)<br>from 表<br>[where 筛选条件]<br>group by 分组<br>[having 字句]<br>[order by 字句]</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/16099.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/16099.html" class="post-title-link" itemprop="url">MySQL常见函数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-01-26 00:00:00" itemprop="dateCreated datePublished" datetime="2019-01-26T00:00:00+08:00">2019-01-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/16099.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/16099.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="字符函数"><a href="#字符函数" class="headerlink" title="字符函数"></a>字符函数</h1><ol>
<li>length 获取参数值中的字节个数</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">select length(&#x27;join&#x27;);  --    4</span><br><span class="line">select length(&#x27;红楼梦&#x27;); --    9</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>concat 拼接字符串</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT concat(&#x27;2020&#x27;,&#x27;-&#x27;,10);   --  2020-10</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>upper lower 大小写转化</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT upper(&#x27;aBc&#x27;);    --  ABC</span><br><span class="line">SELECT lower(&#x27;aBc&#x27;);    --  abc</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>substr substring 截取从指定索引处后面所有字符(索引从1开始)</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT substr(&#x27;1234&#x27;, 2);   --  234</span><br><span class="line">SELECT substring(&#x27;1234&#x27;, 2);   --  234</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>instr 返回字符串字串第一次出现的索引</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select instr(&#x27;abcde&#x27;, &#x27;b&#x27;)  --  2;</span><br></pre></td></tr></table></figure>

<ol start="6">
<li>trim</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">select trim(&#x27; 123 &#x27;); -- 123</span><br><span class="line">select trim(&#x27;a&#x27; from &#x27;abcdea&#x27;); --  bcde</span><br></pre></td></tr></table></figure>

<ol start="7">
<li>lpad rpad 用指定的字符串填充</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT lpad(&#x27;123&#x27;, 5, &#x27;0&#x27;); --  00123</span><br></pre></td></tr></table></figure>

<ol start="8">
<li>replace 替换</li>
</ol>
<p>select replace (‘abcdf’, ‘f’,’e’);</p>
<ol start="9">
<li>SUBSTRING_INDEX</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">DO @str := &#x27;www.baidu.com&#x27;;</span><br><span class="line">SELECT substring_index(@str, &#x27;.&#x27;, 1); --    www</span><br><span class="line">SELECT substring_index(@str, &#x27;.&#x27;, -1); --    com</span><br></pre></td></tr></table></figure>

<h1 id="数学函数"><a href="#数学函数" class="headerlink" title="数学函数"></a>数学函数</h1><ol>
<li>round 四舍五入</li>
</ol>
<p>select round(1.65);</p>
<p>select round(1.655, 2);</p>
<ol start="2">
<li><p>ceil 天花板数</p>
</li>
<li><p>floor 地板数</p>
</li>
<li><p>truncate 截断</p>
</li>
</ol>
<p>select truncate(1.999, 2);</p>
<ol start="5">
<li>mod 取余</li>
</ol>
<h1 id="日期函数"><a href="#日期函数" class="headerlink" title="日期函数"></a>日期函数</h1><ol>
<li><p>now 返回当前系统日期时间</p>
</li>
<li><p>curdate 返回当前系统日期</p>
</li>
<li><p>curtime 返回当前的时间</p>
</li>
<li><p>year month day hour minute second 获取年月日时分秒</p>
</li>
<li><p>str_to_date 将日期格式的字符串转化成指定格式的时间</p>
</li>
</ol>
<table>
<thead>
<tr>
<th>格式符</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>%Y</td>
<td>四位数年份</td>
</tr>
<tr>
<td>%y</td>
<td>两位数年份</td>
</tr>
<tr>
<td>%m</td>
<td>月份(01,02,…12)</td>
</tr>
<tr>
<td>%c</td>
<td>月份(1,2,…12)</td>
</tr>
<tr>
<td>%d</td>
<td>日(01,02,…)</td>
</tr>
<tr>
<td>%H</td>
<td>小时(24)</td>
</tr>
<tr>
<td>%h</td>
<td>小时(12)</td>
</tr>
<tr>
<td>%i</td>
<td>分钟</td>
</tr>
<tr>
<td>%s</td>
<td>秒</td>
</tr>
</tbody></table>
<ol start="6">
<li>date_format 将日期转化成字符</li>
</ol>
<h1 id="其他函数"><a href="#其他函数" class="headerlink" title="其他函数"></a>其他函数</h1><ul>
<li>coalesce<ul>
<li>返回第一个不是 NULL 的值</li>
</ul>
</li>
<li>database</li>
<li>user</li>
<li>version</li>
</ul>
<h1 id="流程控制函数"><a href="#流程控制函数" class="headerlink" title="流程控制函数"></a>流程控制函数</h1><ol>
<li>if</li>
</ol>
<p>select if(10&lt;5, ‘y’, ‘n’);</p>
<ol start="2">
<li>case</li>
</ol>
<p>使用一(类似switch)<br>case 要判断的字段或表达式<br>when 常量 then 要显示的值或语句1;<br>when 常量 then 要显示的值或语句2;<br>…<br>else 都没有命中的时候<br>end;</p>
<p>select salary,department_id<br>case 1 then salary<em>1.1<br>case 2 then salary</em>1.2<br>else salary<br>end from emplory;</p>
<p>使用二(多重if)</p>
<p>case<br>when 条件1 then 要显示的内容1<br>when 条件2 then 要显示的内容2</p>
<h1 id="多行函数-聚合函数"><a href="#多行函数-聚合函数" class="headerlink" title="多行函数(聚合函数)"></a>多行函数(聚合函数)</h1><p>sum avg max min count</p>
<p>特点:</p>
<ol>
<li>sum avg用于处理数值类型,max min count可以处理其他</li>
<li>忽略null值</li>
<li>可以和distinct搭配实现去重</li>
<li>count统计行数,count(*)效率较高</li>
<li>和分组函数一同查询字段要求是group by之后的字段</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># count函数详细介绍</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span> <span class="built_in">count</span>(salary) <span class="keyword">FROM</span> employees;</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span> <span class="built_in">count</span>(<span class="operator">*</span>) <span class="keyword">FROM</span> employees; # 和上着的区别在于,这个展示的是行数,上个取得是除<span class="keyword">null</span>之后的数</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="built_in">count</span>(<span class="number">1</span>) <span class="keyword">from</span> employees; # 相当于数据多了一行<span class="number">1</span>,然后统计个数(实际就是行数)</span><br></pre></td></tr></table></figure>

<h1 id="any-some-all-in-exists"><a href="#any-some-all-in-exists" class="headerlink" title="any some all in exists"></a>any some all in exists</h1><p>exists用于检查子查询是否至少会返回一行数据，该子查询实际上并不返回任何数据，而是返回值True或False。<br>any对于子查询返回的列中的任一数值，如果比较结果为true，则返回true。<br>some是any的别名。<br>all对于子查询返回的列中的所有值，如果比较结果为true，则返回true。</p>
<p>使用方法如下，注意any&#x2F;all&#x2F;是和比较操作符一起使用的</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> TableIn <span class="keyword">where</span> <span class="keyword">exists</span>(<span class="keyword">select</span> BID <span class="keyword">from</span> TableEx <span class="keyword">where</span> BNAME<span class="operator">=</span>TableIn.ANAME);</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> TableIn <span class="keyword">where</span> ANAME<span class="operator">=</span><span class="keyword">ANY</span>(<span class="keyword">select</span> BNAME <span class="keyword">from</span> TableEx);</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> TableIn <span class="keyword">where</span> ANAME <span class="keyword">IN</span> (<span class="keyword">select</span> BNAME <span class="keyword">FROM</span> TableEx);</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> TableIn <span class="keyword">where</span> ANAME<span class="operator">=</span><span class="keyword">ALL</span>(<span class="keyword">select</span> BNAME <span class="keyword">from</span> TableEx);</span><br></pre></td></tr></table></figure>
<p>这里提一下，估计之后看到的时候也会忘记为什么了。in和exists意义并不完全相同，在字段有null值存在的情况，使用两种方法获得的结果可能会不一样。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span></span><br><span class="line"><span class="keyword">FROM</span> test</span><br><span class="line"><span class="keyword">WHERE</span> id <span class="keyword">IN</span> (<span class="keyword">NULL</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span></span><br><span class="line"><span class="keyword">FROM</span> test</span><br><span class="line"><span class="keyword">WHERE</span> <span class="keyword">exists</span>(<span class="keyword">SELECT</span> <span class="keyword">NULL</span>);</span><br></pre></td></tr></table></figure>
<p>如上，第一个查不到数据，第二个查出了test表的所有数据。<br>产生这样的结果，是因为EXISTS 谓词永远不会返回 unknown (select null 的结果是「unknown」，表示未知) 。EXISTS 只会返回 true 或者false 。因此就有了 IN 和 EXISTS 可以互相替换使用，而 NOT IN和 NOT EXISTS 却不可以互相替换的混乱现象。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/20513.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/20513.html" class="post-title-link" itemprop="url">MySql表分区</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-20 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-20T00:00:00+08:00">2018-12-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/20513.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/20513.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h3 id="什么是表分区"><a href="#什么是表分区" class="headerlink" title="什么是表分区"></a>什么是表分区</h3><p>分区是将一个大表,根据条件分割成若干个小表.mysql5.1开始支持表分区,5.5支持表分区的所有函数</p>
<h3 id="为什么要对表进行分区"><a href="#为什么要对表进行分区" class="headerlink" title="为什么要对表进行分区"></a>为什么要对表进行分区</h3><blockquote>
<p>为了改善大型表以及具有各种访问模式的表的可伸缩性,客观理性和提高数据库效率</p>
</blockquote>
<p>分区的一些优点包括</p>
<ul>
<li>与单个磁盘或文件系统相比,可以存储更多的数据</li>
<li>通过删除与增加那些数据有关的分区,很容易地删除或增加那些数据(比如直接truncate一张表比delete where快多了)</li>
<li>一些查询可以得到极大的优化</li>
<li>通过跨多个磁盘甚至服务器来分散数据查询,来获得更高的查询吞吐量</li>
<li>MySql5.5之后支持所有函数的分区优化</li>
</ul>
<h3 id="基本分区类型"><a href="#基本分区类型" class="headerlink" title="基本分区类型"></a>基本分区类型</h3><h4 id="RANGE分区"><a href="#RANGE分区" class="headerlink" title="RANGE分区"></a>RANGE分区</h4><ul>
<li>基于属于一个给定连续区间的列值,把多行分配给分区</li>
<li>这些区间要连续且不能相互重叠,使用values less than操作符来进行定义<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ALERT <span class="keyword">TABLE</span> titles</span><br><span class="line"><span class="keyword">partition</span> <span class="keyword">by</span> <span class="keyword">range</span>(<span class="keyword">year</span>(from_date))</span><br><span class="line">(</span><br><span class="line">  partion p01 <span class="keyword">values</span> less than (<span class="number">1985</span>),</span><br><span class="line">  partion p02 <span class="keyword">values</span> less than (<span class="number">1995</span>),</span><br><span class="line">  partion p03 <span class="keyword">values</span> less than (<span class="number">2005</span>),</span><br><span class="line">  partion p04 <span class="keyword">values</span> less than (<span class="number">2015</span>),</span><br><span class="line">  partion p05 <span class="keyword">values</span> less than (MAXVALUE),</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t1</span><br><span class="line">(</span><br><span class="line">  id   <span class="type">int</span>,</span><br><span class="line">  name <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">  age  <span class="type">int</span></span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> <span class="keyword">RANGE</span> (age)</span><br><span class="line">    (</span><br><span class="line">    <span class="keyword">PARTITION</span> p01 <span class="keyword">VALUES</span> LESS THAN (<span class="number">10</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p02 <span class="keyword">VALUES</span> LESS THAN (<span class="number">20</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p03 <span class="keyword">VALUES</span> LESS THAN (<span class="number">30</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p04 <span class="keyword">VALUES</span> LESS THAN (MAXVALUE)</span><br><span class="line">    );</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="LIST分区"><a href="#LIST分区" class="headerlink" title="LIST分区"></a>LIST分区</h4><ul>
<li>类似于按RANGE分区,区别在于LIST分区是基于列值匹配一个离散值集合中的某个值来进行选择</li>
<li>LIST分区通过使用”partition by list(expr)”来实现,其中”expr”是某列值或一个基于某个列值并返回一个证书的表达式,然后通过”value in (value_list)”的方式来定义每个分区,其中”value_list”是一个通过通过逗号分隔的整数列表</li>
<li>在MySQL5.1中,list分区默认只能匹配整数表.现在5.5已经解决<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t2</span><br><span class="line">(</span><br><span class="line">  id       <span class="type">int</span>,</span><br><span class="line">  cid      <span class="type">int</span>,</span><br><span class="line">  NAME     <span class="type">VARCHAR</span>(<span class="number">20</span>),</span><br><span class="line">  pos_date datetime</span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> LIST (cid)</span><br><span class="line">    (</span><br><span class="line">    <span class="keyword">PARTITION</span> p01 <span class="keyword">VALUES</span> <span class="keyword">IN</span> (<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p02 <span class="keyword">VALUES</span> <span class="keyword">IN</span> (<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p03 <span class="keyword">VALUES</span> <span class="keyword">IN</span> (<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>)</span><br><span class="line">    );</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="HASH分区"><a href="#HASH分区" class="headerlink" title="HASH分区"></a>HASH分区</h4><ul>
<li>基于用户定义的表达式的返回值来进行选择的分区,该表达式使用将要插入到表中的这些行的列值进行计算.这个表达式可以包含MySQL中有效的,产生非负整数值的任何表达式</li>
<li>使用HASH分区的优点在于数据分布较为均匀</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t3</span><br><span class="line">(</span><br><span class="line">  id       <span class="type">int</span>,</span><br><span class="line">  cid      <span class="type">int</span>,</span><br><span class="line">  name     <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">  pos_date datetime</span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> HASH (cid)</span><br><span class="line">    PARTITIONS <span class="number">4</span></span><br></pre></td></tr></table></figure>

<h4 id="linear-hash分区"><a href="#linear-hash分区" class="headerlink" title="linear hash分区"></a>linear hash分区</h4><ul>
<li>线性与常规哈希的区别在于,线性哈希功能使用的一个线性的2的幂(powers-of-two)运算规则,而常规哈希使用的时求哈希函数值的模数.</li>
<li>按照线性哈希分区的优点在于增加 删除 合并 和 拆分分区将变得更加快捷,有利于处理含有极大量(1t)数据的表.不过,mysql的线性哈希算法导致相比较常规哈希,数据可能分布的不那么均匀,容易产生”hotspot nodes”<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t3</span><br><span class="line">(</span><br><span class="line">  id       <span class="type">int</span>,</span><br><span class="line">  cid      <span class="type">int</span>,</span><br><span class="line">  name     <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">  pos_date datetime</span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> linear HASH (cid)</span><br><span class="line">    PARTITIONS <span class="number">4</span></span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="KEY分区"><a href="#KEY分区" class="headerlink" title="KEY分区"></a>KEY分区</h3><ul>
<li>类似于哈希分区,哈希分区使用的用户定义的表达式,而key分区的哈希函数是由mysql服务器提供.mysql簇(cluster)使用函数md5()来实现key分区;对于使用其他存储引擎的表,服务器使用其自己内部的哈希函数.这些函数时基于password()一样的运算法则</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t4</span><br><span class="line">(</span><br><span class="line">  id       <span class="type">int</span>,</span><br><span class="line">  cid      <span class="type">int</span>,</span><br><span class="line">  name     <span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">  pos_date datetime</span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> [linear] KEY (cid)</span><br><span class="line">    PARTITIONS <span class="number">4</span>;</span><br></pre></td></tr></table></figure>

<h3 id="多列分区"><a href="#多列分区" class="headerlink" title="多列分区"></a>多列分区</h3><ul>
<li>columns关键字允许字符串和日期列作为分区定义列,同时还允许使用多个列定义一个分区</li>
</ul>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t5</span><br><span class="line">(</span><br><span class="line">  id       <span class="type">int</span>,</span><br><span class="line">  cid      <span class="type">int</span></span><br><span class="line">)</span><br><span class="line">  <span class="keyword">PARTITION</span> <span class="keyword">BY</span> <span class="keyword">RANGE</span> COLUMNS (id, cid)</span><br><span class="line">    (</span><br><span class="line">    <span class="keyword">PARTITION</span> p01 <span class="keyword">VALUES</span> LESS THAN (<span class="number">10</span>,<span class="number">10</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p02 <span class="keyword">VALUES</span> LESS THAN (<span class="number">10</span>,<span class="number">20</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p03 <span class="keyword">VALUES</span> LESS THAN (<span class="number">10</span>,<span class="number">30</span>),</span><br><span class="line">    <span class="keyword">PARTITION</span> p04 <span class="keyword">VALUES</span> LESS THAN (<span class="number">10</span>,MAXVALUE ),</span><br><span class="line">    <span class="keyword">PARTITION</span> p05 <span class="keyword">VALUES</span> LESS THAN (MAXVALUE ,MAXVALUE )</span><br><span class="line">    );</span><br></pre></td></tr></table></figure>

<h3 id="子分区"><a href="#子分区" class="headerlink" title="子分区"></a>子分区</h3><ul>
<li>子分区是分区别中每个分区的再次分割</li>
<li>子分区可以用于特别大的表,在多个磁盘间分配数据和索引</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/43624.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/43624.html" class="post-title-link" itemprop="url">原生js触发事件</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-18 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-18T00:00:00+08:00">2018-12-18</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:45" itemprop="dateModified" datetime="2022-04-15T13:54:45+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js/" itemprop="url" rel="index"><span itemprop="name">js</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/43624.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/43624.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>遇到个视频在浏览器中不能播放的原因.后查询得知现在的chrome和safari不能直接播放带声音的声音<a target="_blank" rel="noopener" href="https://m.huanqiu.com/r/MV8wXzk0Nzc2MDRfNjEyXzE0NzQ1OTMxODA=">苹果与谷歌移动浏览器添加视频自动播放功能</a></p>
<p>另附 <a target="_blank" rel="noopener" href="http://www.zanmeishi.com/help/20.html">safari直接播放带音频的视频的配置方法</a></p>
<p>然后我就想着能不能利用jQuery中的trigger来实现视频音频自动播放</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">video</span> <span class="attr">autoplay</span>=<span class="string">&quot;autoplay&quot;</span> <span class="attr">loop</span>=<span class="string">&quot;loop&quot;</span> <span class="attr">id</span>=<span class="string">&quot;bg-video&quot;</span> &gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">source</span> <span class="attr">src</span>=<span class="string">&quot;image/upload/video/weizhen.mp4&quot;</span> <span class="attr">type</span>=<span class="string">&quot;video/mp4&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">source</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">video</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">id</span>=<span class="string">&quot;test&quot;</span>&gt;</span>点击播放按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">window</span>.<span class="property">onload</span> = <span class="keyword">function</span> (<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="title function_">trigger</span>();</span></span><br><span class="line"><span class="language-javascript">    &#125;;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;test&#x27;</span>).<span class="property">onclick</span> = <span class="keyword">function</span> (<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="title function_">alert</span>(<span class="string">&#x27;click&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> res =  <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;bg-video&#x27;</span>).<span class="title function_">play</span>();</span></span><br><span class="line"><span class="language-javascript">    &#125;;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="keyword">function</span> <span class="title function_">trigger</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">if</span>(<span class="variable language_">document</span>.<span class="property">all</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;test&quot;</span>).<span class="title function_">click</span>();</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">else</span> &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> e = <span class="variable language_">document</span>.<span class="title function_">createEvent</span>(<span class="string">&quot;MouseEvents&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            e.<span class="title function_">initEvent</span>(<span class="string">&quot;click&quot;</span>, <span class="literal">true</span>, <span class="literal">true</span>);<span class="comment">//这里的click可以换成你想触发的行为</span></span></span><br><span class="line"><span class="language-javascript">            <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;test&quot;</span>).<span class="title function_">dispatchEvent</span>(e);<span class="comment">//这里的clickME可以换成你想触发行为的DOM结点</span></span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    &#125;</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>可事实证明,这个投机方法是无用的.浏览器已经做了处理.依然必须要手动触发才行</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/63488.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/63488.html" class="post-title-link" itemprop="url">MySQL之You can't specify target table for update in FROM clause解决办法</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-06 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-06T00:00:00+08:00">2018-12-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/63488.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/63488.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>750</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>mysql并不支持对同一表的数据作为同一表的更新数据.</p>
<p>如</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span></span><br><span class="line"><span class="keyword">FROM</span> vip_reward_record</span><br><span class="line"><span class="keyword">WHERE</span> type <span class="operator">=</span> <span class="number">1</span></span><br><span class="line">  <span class="keyword">AND</span> id <span class="keyword">NOT</span> <span class="keyword">IN</span> (<span class="keyword">SELECT</span> <span class="built_in">max</span>(id) <span class="keyword">FROM</span> vip_reward_record <span class="keyword">WHERE</span> type <span class="operator">=</span> <span class="number">1</span> <span class="keyword">GROUP</span> <span class="keyword">BY</span> member_id);</span><br></pre></td></tr></table></figure>
<p>这样就中提示 <code>You can&#39;t specify target table for update in FROM claus</code></p>
<p>但解决也不难<br>在select外边套一层，让数据库认为你不是查同一表的数据作为同一表的更新数据,就向像这要”包装”一层就可以了</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DELETE</span></span><br><span class="line"><span class="keyword">FROM</span> vip_reward_record</span><br><span class="line"><span class="keyword">WHERE</span> type <span class="operator">=</span> <span class="number">1</span></span><br><span class="line">  <span class="keyword">AND</span> id <span class="keyword">NOT</span> <span class="keyword">IN</span> (<span class="keyword">SELECT</span> id <span class="keyword">FROM</span> (<span class="keyword">SELECT</span> <span class="built_in">max</span>(id) <span class="keyword">AS</span> id <span class="keyword">FROM</span> vip_reward_record <span class="keyword">WHERE</span> type <span class="operator">=</span> <span class="number">1</span> <span class="keyword">GROUP</span> <span class="keyword">BY</span> member_id) a);</span><br></pre></td></tr></table></figure>

<p>但是,像是这样,却是可以运行的</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">UPDATE</span> vip_member</span><br><span class="line"><span class="keyword">SET</span> dynamic_reward <span class="operator">=</span> (<span class="keyword">SELECT</span> ifnull(<span class="built_in">sum</span>(times <span class="operator">*</span> least(left_dynamic_reward, right_dynamic_reward) <span class="operator">*</span> <span class="number">2</span> <span class="operator">*</span> <span class="number">0.03</span> <span class="operator">*</span> <span class="number">0.95</span>), <span class="number">0</span>)</span><br><span class="line">                      <span class="keyword">FROM</span> vip_dynamic_reward</span><br><span class="line">                      <span class="keyword">WHERE</span> vip_member.id <span class="operator">=</span> vip_dynamic_reward.member_id);</span><br></pre></td></tr></table></figure>

<p>两者的差距看起来就是update&#x2F;delete之后没有紧跟着where.事实上可以运行的那一句在运行时会提醒<code> Unsafe query: &#39;Update&#39; statement without &#39;where&#39; updates all table rows at once</code></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chenmenghui.gitee.io/posts/41843.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="陈孟辉">
      <meta itemprop="description" content="日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈孟辉的学习笔记">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/posts/41843.html" class="post-title-link" itemprop="url">php使用mysqli</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-06 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-06T00:00:00+08:00">2018-12-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-15 13:54:44" itemprop="dateModified" datetime="2022-04-15T13:54:44+08:00">2022-04-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/41843.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/41843.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>mysqli::prepare()可以避免sql注入,还是挺有用的.但是无法同时执行多个sql语句</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* select</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="variable">$connect</span> = <span class="keyword">new</span> <span class="title function_ invoke__">mysqli</span>(<span class="string">&#x27;localhost&#x27;</span>, <span class="string">&#x27;root&#x27;</span>, <span class="string">&#x27;&#x27;</span>, <span class="string">&#x27;test&#x27;</span>);</span><br><span class="line"><span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">set_charset</span>(<span class="string">&#x27;utf8&#x27;</span>);</span><br><span class="line"><span class="variable">$sql</span> = <span class="string">&quot;SELECT `name`, `age` FROM `user` WHERE `name` = ?&quot;</span>;</span><br><span class="line"><span class="variable">$tmp</span> = <span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">prepare</span>(<span class="variable">$sql</span>);</span><br><span class="line"><span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">bind_param</span>(<span class="string">&#x27;s&#x27;</span>, <span class="variable">$name</span>);</span><br><span class="line"><span class="variable">$name</span> = <span class="string">&#x27;grey&#x27;</span>;</span><br><span class="line"><span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">bind_result</span>(<span class="variable">$name</span>, <span class="variable">$price</span>);</span><br><span class="line"><span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">execute</span>();</span><br><span class="line"><span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">store_result</span>();</span><br><span class="line"><span class="variable">$count</span> = <span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">num_rows</span>(); <span class="comment">// 数量</span></span><br><span class="line"><span class="keyword">echo</span> <span class="variable">$count</span>.<span class="string">&quot;\n&quot;</span>;</span><br><span class="line"><span class="keyword">while</span> (<span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">fetch</span>()) &#123;</span><br><span class="line">    <span class="keyword">echo</span> <span class="string">&quot;<span class="subst">&#123;$name&#125;</span>--<span class="subst">&#123;$price&#125;</span>\n&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">close</span>();</span><br></pre></td></tr></table></figure>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * insert</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="variable">$connect</span> = <span class="keyword">new</span> <span class="title function_ invoke__">mysqli</span>(<span class="string">&#x27;localhost&#x27;</span>, <span class="string">&#x27;root&#x27;</span>, <span class="string">&#x27;&#x27;</span>, <span class="string">&#x27;test&#x27;</span>);</span><br><span class="line"><span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">set_charset</span>(<span class="string">&#x27;utf8&#x27;</span>);</span><br><span class="line"><span class="variable">$sql</span> = <span class="string">&quot;INSERT INTO user (`name`, `age`) VALUE (?, ?)&quot;</span>;</span><br><span class="line"><span class="variable">$tmp</span> = <span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">prepare</span>(<span class="variable">$sql</span>);</span><br><span class="line"><span class="keyword">if</span>(!<span class="variable">$tmp</span> ) &#123;</span><br><span class="line">    <span class="keyword">die</span>(<span class="variable">$connect</span>-&gt;error);</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">bind_param</span>(<span class="string">&#x27;sd&#x27;</span>, <span class="variable">$name</span>, <span class="variable">$age</span>);</span><br><span class="line"></span><br><span class="line"><span class="variable">$names</span> = <span class="keyword">array</span>(<span class="string">&quot;Neo&quot;</span>, <span class="string">&quot;Morpheus&quot;</span>, <span class="string">&quot;Trinity&quot;</span>, <span class="string">&quot;Cypher&quot;</span>, <span class="string">&quot;Tank&quot;</span>);</span><br><span class="line"><span class="keyword">for</span> (<span class="variable">$i</span> = <span class="number">0</span>; <span class="variable">$i</span> &lt; <span class="number">3</span>; <span class="variable">$i</span>++) &#123; <span class="comment">// 一次进行多次操作,以execute之前的最后一个（被绑定的）参数为准，即使这个参数在prepare之前</span></span><br><span class="line">    <span class="variable">$name</span> = <span class="variable">$names</span>[<span class="title function_ invoke__">array_rand</span>(<span class="variable">$names</span>)];</span><br><span class="line">    <span class="variable">$age</span> = <span class="variable">$i</span>;</span><br><span class="line">    <span class="variable">$tmp</span>-&gt;<span class="title function_ invoke__">execute</span>();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="variable">$connect</span>-&gt;<span class="title function_ invoke__">close</span>();</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/12/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/12/">12</a><span class="page-number current">13</span><a class="page-number" href="/page/14/">14</a><span class="space">&hellip;</span><a class="page-number" href="/page/17/">17</a><a class="extend next" rel="next" href="/page/14/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">陈孟辉</p>
  <div class="site-description" itemprop="description">日积月藏，不做咸鱼。这里是陈孟辉的个人学习笔记，现就职于北京瑞友科技，负责维护企业ERP系统。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">170</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">45</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">60</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://tool.oschina.net/uploads/apidocs/jquery/regexp.html" title="http:&#x2F;&#x2F;tool.oschina.net&#x2F;uploads&#x2F;apidocs&#x2F;jquery&#x2F;regexp.html" rel="noopener" target="_blank">正则表达式</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://www.cs.usfca.edu/~galles/visualization/Algorithms.html" title="https:&#x2F;&#x2F;www.cs.usfca.edu&#x2F;~galles&#x2F;visualization&#x2F;Algorithms.html" rel="noopener" target="_blank">算法图示</a>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">陈孟辉</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">204k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">3:06</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>

<script src="/js/utils.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : true,
      notify     : true,
      appId      : '9jQqXQuURk2dvsv5oVh9D0VM-gzGzoHsz',
      appKey     : 'YfjrSNHQAtj63yeNmdmrLlLw',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : true,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
